class FirstPage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [
                { ismode: 1 },
            ],
            thumburl: '',
            name: '',
            fangjianhtml: [],
            input_name: '',
            sdarr: [],
            showpage:!1,
            showbtn:!0,
            sel_fang: -1,
            showpage1:!1,
            select1id:-1,
            priceitem:{},
            mbkjlist: [

            ],//模板空间
            id: '0',
            partcount: 1,
            parts: [{ src: '' }, { src: '' }, { src: '' }],
            categorylist: [],
            select_swiperlink: { name: '请选择' },
            swiperimglist: [],
            input_mbname: '模板房间',
            category_select_list: [],
            recommendtablehtml: [],
            recommendlist: [],
            detail: { id: -1, name: '' },
            goods_select_html: [],
            currentswipertype: 0,
            swiperlinkhtml: [],
            swipertablehtml: [],
            swiperimghtml: [],
            subtitle: '',
            totalamount: 0,
            showmoban: !1,
            showeditprice:!1,
            moban: {
                cp: [
                    { width: 0, height: 0, deep: 0, singleprice: 0 }
                ],
                wj: [
                    { count: 0, singleprice: 0 }

                ],
                name: '',
                amount: 0
            },
            exportlist: [

            ],
            swiper: {
                imgs: [],
                links: []
            },
            fileimgshow: !0,
            imgstate: '',
            imgsrc: '',
            to: '',
        };
    }

    formatlist(list) {
        console.log('1232345234');
        list.forEach((x, i) => {
            if (!x.items['cp']) {
                // console.log("x.items['cp']");
                let items = {}
                items['cp'] = x.items.filter(x => { return x.type == 'CP' })
                items['wj'] = x.items.filter(x => { return x.type == 'WJ' })
                list[i]['items'] = items
            }
        })
        console.log(list, 'format--list');
        this.setState({ exportlist: list })
    }


    getxs(deep) {

        let ii=-1,{sdarr} = this.state;
        this.state.sdarr.forEach((x,i) => {
            if (deep > x.min && deep <= x.max) ii = i
        })
        let res = ii==-1?1:sdarr[ii].number
       // console.log({deep,res},'getxs');

        return res;
    }

    firstgetdata(id){
        let  totalamount = 0, fangjianhtml = []
        dzroom_getlist(res => {
            if (res.issuccess == 1) {
                fangjianhtml.push(<option value={-1}>请选择 </option>)
                res.list.forEach((x, i) => {
                    fangjianhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>
                    )
                })
                this.setState({ roomlist: res.list, fangjianhtml })
            }
        })

        dz_categetlist(res => {
            if (res.issuccess == 1) {
                let { list } = res

                let cate_CPLBhtml = [], cate_GTCZhtml = [], cate_WJLBhtml = [], cate_WJCZhtml = [],cate_MBXHhtml=[],cate_LSFShtml=[],cate_GTXHhtml=[];
                let list_CPLB = list.filter(x => x.type == 'CPLB')
                let list_GTCZ = list.filter(x => x.type == 'GTCZ')
                let list_WJLB = list.filter(x => x.type == 'WJLB')
                let list_WJCZ = list.filter(x => x.type == 'WJCZ')
                let list_MBXH = list.filter(x => x.type == 'MBXH')
                let list_LSFS = list.filter(x => x.type == 'LSFS')
                let list_GTXH = list.filter(x => x.type == 'GTXH')
                let list_XSSD = list.filter(x => x.type == 'XSSD')
              //  console.log({ list_CPLB, list_GTCZ, list_WJLB, list_WJCZ }, 'list1');


              cate_LSFShtml.push(<option value={-1}>请选择 </option>)
              list_LSFS.forEach((x, i) => {
                cate_LSFShtml.push(
                      <option key={i} value={x.id}>
                        {x.name} 
                        </option>
                  )
              })

              cate_GTXHhtml.push(<option value={-1}>请选择 </option>)
              list_GTXH.reverse().forEach((x, i) => {
                cate_GTXHhtml.push(
                      <option key={i} value={x.id}>{x.name} 
                      </option>
                      
                  )
              })

              cate_MBXHhtml.push(<option value={-1}>请选择 </option>)
              list_MBXH.reverse().forEach((x, i) => {
                cate_MBXHhtml.push(
                      <option key={i} value={x.id}>{x.name} 
                      </option>
                  )
              })

                cate_CPLBhtml.push(<option value={-1}>请选择 </option>)
                list_CPLB.reverse().forEach((x, i) => {
                    cate_CPLBhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>
                    )
                })

                cate_GTCZhtml.push(<option value={-1}>请选择 </option>)
                list_GTCZ.reverse().forEach((x, i) => {
                    cate_GTCZhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>
                    )
                })

                cate_WJLBhtml.push(<option value={-1}>请选择 </option>)
                list_WJLB.reverse().forEach((x, i) => {
                    cate_WJLBhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>
                    )
                })

                cate_WJCZhtml.push(<option value={-1}>请选择 </option>)
                list_WJCZ.reverse().forEach((x, i) => {
                    cate_WJCZhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>
                    )
                })

                // catehtml1.push(<option value={-1}>请选择</option>)
                // res.list1.forEach((x, i) => {
                //     catehtml1.push(
                //         <option key={i} value={x.id}>{x.name} </option>
                //     )
                
                // })
                if (id != 'null') {
                    this.setState({ id,sdarr:list_XSSD }, () => {
                        dz_projectdetail_getd(id, res => {
                            let detail = res.data
                            // console.log(uniq(res.data.roomids.split(',')),'uniq');
                            if (detail.rawData == '') {
                                dzroom_getlistbyid(
                                    uniq(res.data.roomids.split(',')).toString(), res => {
                                        let { list } = res
                                        if (list.length > 0) {
                                            this.setState({ input_name: res.name })
                                            this.formatlist(list)
                                            // dz_getcategorylist('XSSD', res => {
                                            //     if (res.issuccess == 1) {
                                            //         this.setState({ sdarr: res.list, input_name: res.name }, () => {
                                            //             this.formatlist(list)
                                            //         })
                                            //     }
                                            // })
                                        }
                                    }
                                )
                            } else {
                                // console.log(),'0000');
                                let exportlist = JSON.parse(decodeurl(res.data.rawData))
                                console.log(exportlist, 'listlist123');
                                this.formatlist(exportlist)
        
                                this.setState({ input_name: detail.name })
        
                            }
                        })
                    })
                }




                this.setState({
                    categorylist:list,
                    cate_CPLBhtml, list_CPLB, cate_GTCZhtml, list_GTCZ, list_WJLB,list_LSFS,list_GTXH,list_MBXH
                    , cate_WJLBhtml, cate_WJCZhtml, list_WJCZ,cate_MBXHhtml,cate_LSFShtml,cate_GTXHhtml
                })
            }

        })

    }

    ccheck(id){
        if(id!='null'){
            let pwd = prompt('请输入密码')
            dz_category_checkpwd(md5(pwd + Constant.SALT),res=>{
                if(res.data==true){
                    this.firstgetdata(id)
                }else{
                    // this.ccheck(id)
                    alert('密码错误')
                    window.location.href='./dz_main.html'
                }
            })

        }else{
            this.firstgetdata(id)
        }
    }




    componentDidMount() {
        let id = GetQueryString('id'), totalamount = 0, fangjianhtml = []  
        console.log(id,'idid');
        this.firstgetdata(id)
         //  this.ccheck(id)

    }
    freshlist() {
        dzroom_getlist(res => {
            if (res.issuccess == 1) {

                // this.formatlist(res.list); 
                let roomhtml = [];
                roomhtml.push(<option value={-1}>请选择 </option>)
                res.list.forEach(x => {
                    roomhtml.push(
                        <option value={x.id}>{x.name} </option>
                    )
                })

                this.setState({ list: res.list, roomhtml })

                console.log(res.list)
            }
        })




    }





    /**新建 */
    add() {
        // $('.modal1').show()
        var name = prompt('请输入房间名称')
        if (name != '') {
            aoedzroom({ name }, res => {
                if (res.issuccess == 1) {
                    this.freshlist()
                } else {
                    alert(res.msg)
                }
            })
        }
    }


    // 编辑
    edit(x) {
        var name = prompt('请编辑房间名称', x.name)
        if (name != '' && name != x.name) {
            //  console.log(name,'name');

            dz_projectdetail_add({ id: x.id, name }, res => {
                if (res.issuccess == 1) {
                    //   alert('修改成功')
                    this.freshlist()
                } else {
                    alert(res.msg)
                }
            })
        }

        // 
    }
    tosub(x) {
        window.location.href = "./dz_subcate.html?id=" + x.id + "&name=" + x.name;
    }
    // 排序
    addmoban() {
        if (this.state.showmoban) {
            //保存
            this.savemoban()

        } else {
            let moban = {
                cp: [
                    { width: 0, height: 0, deep: 0, singleprice: 0 }
                ],
                wj: [
                    { count: 0, singleprice: 0 }

                ],
                name: '',
                amount: 0
            }
            // let moban = {
            //     name:'123',
            //     wj:[
            //         {
            //           "count": "300",
            //           "singleprice": "15",
            //           "cid1": 84,
            //           "type": "WJ",
            //           "cname1": "国产品牌DTC铰链",
            //           "unit": "个"
            //         },
            //         {
            //           "count": "400",
            //           "singleprice": "15",
            //           "cid1": 84,
            //           "type": "WJ",
            //           "cname1": "国产品牌DTC铰链",
            //           "unit": "个"
            //         },
            //         {
            //           "count": "200",
            //           "singleprice": "48",
            //           "cid1": 113,
            //           "type": "WJ",
            //           "cname1": "文信长盒子拉手",
            //           "unit": "个"
            //         }
            //       ],

            //     cp:[
            //         {
            //           "width": "1000",
            //           "height": "1000",
            //           "deep": 0,
            //           "singleprice": "1000",
            //           "cid1": 78,
            //           "type": "CP",
            //           "cname1": "门板 | 柜体",
            //           "unit": "平方"
            //         },
            //         {
            //           "width": "2000",
            //           "height": "2000",
            //           "deep": 0,
            //           "singleprice": "798",
            //           "cid1": 50,
            //           "type": "CP",
            //           "cname1": "门板国产欧松板 | 柜体国产欧松板",
            //           "unit": "平方"
            //         },
            //         {
            //           "width": "3000",
            //           "height": "32000",
            //           "deep": 0,
            //           "singleprice": "880",
            //           "cid1": 41,
            //           "type": "CP",
            //           "cname1": "开放格（福人）",
            //           "unit": "平方"
            //         }
            //       ],
            // }



            this.setState({ moban, showmoban: !0 })
        }





    }

    addline(index, type,iindex) {
        
        if (this.state.input_name == '') {
            alert('请输入业主地址')
        } else {
            let { exportlist } = this.state
           // exportlist[index]['items'][type == 'CP' ? 'cp' : 'wj'].push({ count: 0, type, id: 0, width: 0, height: 0, deep: 0, singleprice: 0 })
            exportlist[index]['items'][type == 'CP' ? 'cp' : 'wj'].splice(iindex+1,0,{ count: 0,cname1:-1, type, id: 0, width: 0, height: 0, deep: 0, singleprice: 0 })
            //  this.setState({exportlist})
            this.save(exportlist)
        }
    }

    removeline(i, oi, t) {
        console.log({ i, oi, t }, 'removeline');
        let { exportlist } = this.state, items = exportlist[i]['items'][t == 'CP' ? 'cp' : 'wj'];
        if (items.length == 1) {
            items.push({ count: 0, type: t, id: 0, width: 0, height: 0, deep: 0, singleprice: 0 })
        } else {
            items.splice(oi, 1)
        }
        exportlist[i]['items'][t == 'CP' ? 'cp' : 'wj'] = items
        // this.setState({exportlist})
        this.save(exportlist)

        //每次删除都要重新设置一边oindex


        //    let list = this.state.exportlist[i]['items'].filter(x=>{return x.type==t})
        //   //  let {moban} = this.state

        //     if(e==0){
        //         moban.cp.splice(i,1)
        //     }else{
        //         moban.wj.splice(i,1)
        //     }
        //     // let {moban} = this.state,data = [{}]
        //     // moban[`${e==0?'cp':'wj'}`].push(data)
        //      this.setState({moban})
    }




    // 删除
    del(e, cid) {
        this.setState({ delid: e, newcid: cid }, () => {
            $('#myModal').modal('toggle');
        })
    }

    delroom(index) {
        var b = confirm('确定要删除房间吗')
        if (b) {
            let { exportlist } = this.state
            exportlist.splice(index, 1)
            this.save(exportlist)
        }
    }



    confirmdel() {
        let { delid, start } = this.state
        delimg(delid, res => {
            if (res.issuccess == 1) {
                //  alert('删除成功')
                $('#myModal').modal('toggle');
                this.freshlist(start)
            } else {
                $('#myModal').modal('toggle');
                alert(res.msg);
            }
        })
    }

    closemodal() {
        $('.modal1').hide()
    }

    inputchange(prop, e) {
        this.setState({ [prop]: e.target.value })
    }
    confirm() {
        let { name, subtitle } = this.state, err = '';
        if (name.length == 0) err = '请输入名称'
        dz_project_aoe({ name, subtitle }, res => {
            $('.modal1').hide()
            if (res.issuccess == 1) {
                //   alert('提交成功')
                this.freshlist()
            }
        })
    }

    toitem(id) {
        window.location.href = './dz_item.html?id=' + id
    }

    // selectchange(e){
    //     this.setState({selectroomid:e.target.value})
    // }

    selectchange(ei, t, index, e) {
        //  if(this.state.detail.pool!='BJ') return

        let { value } = e.target, { exportlist } = this.state, tname = t == 'CP' ? 'cp' : 'wj', list = t == 'CP' ? this.state.list_GTCZ : this.state.list_WJLB, item = list.find(x => x.id == value), i = 0;
        console.log('here-selectchange', { ei, t, e, index, item });
        // if (id > 0) {
        //     i = exportlist[ei]['items'].findIndex(x => { return x.id == id })
        // } else {
        //     //自定义里的 
        //     // if(t=='WJLB'){
        //     //     index+=exportlist[ei]['items'].filter(x=>{return x.type=='CP'}).length
        //     // }
        //     i = exportlist[ei]['items'].findIndex(x => { return x.oindex == index })
        // }
        //console.log(i, 'selectchange--i');
        exportlist[ei]['items'][tname][index]['cid1'] = item.id;
        exportlist[ei]['items'][tname][index]['type'] = t
        exportlist[ei]['items'][tname][index]['cname1'] = item.name;
        exportlist[ei]['items'][tname][index]['singleprice'] = item.price;
        exportlist[ei]['items'][tname][index]['unit'] = item.unit;
        if(item.unit=='扇'){
            console.log(exportlist[ei]['items'][tname][index]['count'],'countt');
            exportlist[ei]['items'][tname][index]['count'] = 1;

        }
        this.setState({ exportlist }, () => {
            this.save(exportlist)
        })
    }


    selectchange1(ei, t, index, e) {
        //  if(this.state.detail.pool!='BJ') return

        console.log('here-selectchange1', { ei, t, e, index });
        let { value } = e.target, { exportlist } = this.state, tname = 'cp', 
        list =t=='LSFS'? this.state.list_LSFS : 
        t=='GTXH'? this.state.list_GTXH : this.state.list_MBXH, item = list.find(x => x.id == value), i = 0;
        console.log('here-selectchange1', { ei, t, e, index, item });
        // if (id > 0) {
        //     i = exportlist[ei]['items'].findIndex(x => { return x.id == id })
        // } else {
        //     //自定义里的 
        //     // if(t=='WJLB'){
        //     //     index+=exportlist[ei]['items'].filter(x=>{return x.type=='CP'}).length
        //     // }
        //     i = exportlist[ei]['items'].findIndex(x => { return x.oindex == index })
        // }
        //console.log(i, 'selectchange--i');
        exportlist[ei]['items'][tname][index][t+"id"] = item.id;
        exportlist[ei]['items'][tname][index][t+"src"] = item.imgurl;
        exportlist[ei]['items'][tname][index]['type'] = t
        exportlist[ei]['items'][tname][index][t+'name'] = item.name;
        // exportlist[ei]['items'][tname][index]['singleprice'] = item.price;
        // exportlist[ei]['items'][tname][index]['unit'] = item.unit;
        this.setState({ exportlist }, () => {
            this.save(exportlist)
        })
    }


    savemoban() {
        let { input_name } = this.state
        if (input_name == '') {
            alert('请输入业主地址')
            return
        } else {
            let { moban, exportlist } = this.state, data = {
                name: this.state.input_mbname,
                items: {
                    cp: [{ width: 0, height: 0, deep: 0, singleprice: 0 }]
                    , wj: [{ count: 0, singleprice: 0 }]
                }
            }
            exportlist.push(data)
            this.save(exportlist)


            this.setState({
                exportlist, moban: {
                    cp: [
                        { width: 0, height: 0, deep: 0, singleprice: 0 }
                    ],
                    wj: [
                        { count: 0, singleprice: 0 }

                    ],
                    name: '',
                    amount: 0
                }
            })
        }
    }

    export1() {
      //  let {showeditprice} = this.state

        this.setState({showpage:!0,showbtn:!1,showeditprice:!1},()=>{
            window.print()
        })
        setTimeout(() => { 
            this.setState({showpage:!1,showbtn:!0})
        });
    }

    export() {



        let { exportlist, detail } = this.state;

        let str = '总屋名称,' + detail.name
        //`${topname}\n${housename}\n产品类型,高,宽,深度,单价,数量,总价,单位,立面说明,门板材质/柜体材质\n`
        const jsonData = []
        let total = 0;
        let totalcount = 0;
        // <td className="tconter">{((Number(x.height)* Number(x.width))/1000000).toFixed(2)}</td>
        //                                    <td className="tconter">{(Number(x.singleprice)* (((Number(x.height)* Number(x.width))/1000000).toFixed(2))).toFixed(2)}</td>

        console.log(exportlist, 'exportlistexportlist');
        exportlist.forEach(x => {
            str += `\n房间名称,${x.name}\n产品类型,高,宽,深度,数量,单位,单价,总价,立面说明,门板/柜体材质\n`
            x.items.filter(x => { return x.type == 'CP' }).forEach(y => {
                str += `${y.cname},${y.height},${y.width},${y.deep},${y.count},${y.unit},${y.singleprice},${(Number(y.count) * Number(y.singleprice)).toFixed(2)},${y.lmsm},${y.cname1}\n`
            })
            str += `,,,平方总计,${x.cptotalcount},,金额合计,${x.cptotal}\n\n`

            str += `五金类型,高,宽,深度,数量,单位,单价,总价,立面说明,五金材质\n`
            x.items.filter(x => { return x.type == 'WJ' }).forEach(y => {
                str += `${y.cname},-,-,-,${y.count},${y.unit},${y.singleprice},${(Number(y.count) * Number(y.singleprice)).toFixed(2)},${y.lmsm},${y.cname1}\n`
            })
            str += `,,,,,,,,金额合计,${x.wjtotal}\n`
            str += `总金额,${Math.round(Number(x.cptotal) + Number(x.wjtotal))}\n`
            total = Math.round(Number(total) + Number(x.cptotal) + Number(x.wjtotal))
        })
        str += '\n\n总价合计,' + total
        let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
        //通过创建a标签实现
        let link = document.createElement("a");
        link.href = uri;
        //对下载的文件命名
        link.download = name + ".csv";
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);

    }


    addroom() {
        let { selectroomid, exportlist, totalamount } = this.state;
        if (Number(selectroomid) > 0) {
            dz_getprojectitemlist(selectroomid, res => {
                if (res.issuccess == 1) {
                    let { room, wj, cp } = res;
                    let wjtotal = 0, cptotal = 0, cptotalcount = 0, wjtotalcount = 0, amount = 0
                    wj.forEach(x => {
                        wjtotal = (Number(wjtotal) + (Number(x.singleprice) * Number(x.count))).toFixed(2)
                        wjtotalcount = (Number(wjtotalcount) + Number(x.count)).toFixed(2)
                    })
                    cp.forEach(x => {
                        cptotalcount = (Number(cptotalcount) + Number(x.count)).toFixed(2)
                        cptotal = (Number(cptotal) + (Number(x.singleprice) * Number(x.count))).toFixed(2)
                    })
                    amount = (Number(wjtotal) + (Number(cptotal))).toFixed(2)
                    totalamount = (Number(totalamount) + (Number(amount))).toFixed(2)
                    let item = { room, wjtotal, cptotal, cptotalcount, wjtotalcount, amount, wj, cp }
                    console.log(item, 'item');
                    exportlist.push(item)
                    console.log(exportlist, 'exportlist');
                    this.setState({ exportlist, totalamount })
                }
            })
        }
    }

    save(exportlist) {
        let { id, input_name } = this.state;
        if (input_name == '') {
            alert('请输入业主地址')
        } else {
            let data = { name: input_name, rawData: JSON.stringify(exportlist) }
            if (Number(id) > 0) data['id'] = id
            dz_projectdetail_editdata(data, res => {
                if (res.issuccess == 1) {
                    if (Number(id) > 0) {
                    } else {
                        this.setState({ id: res.id })
                    }
                    this.setState({ exportlist })

                    //alert('保存成功')
                    // if(ismoban){
                    //     window.location.href='./dz_newroom.html?id='+res.id
                    // }
                }
            })
        }

    }

    inputchange1(eindex, prop, val, tdindex, type) {

        // var value = prompt('请输入', val)
        // console.log('inputchange1', { eindex, prop, val });
        // if (value != val && value != '' && value != null) {
        //     let { exportlist } = this.state
        //     exportlist[eindex]['items'][type][tdindex][prop] = value
        //     this.setState({ exportlist }, () => {
        //         this.save(exportlist)
        //     })
            // if (id == -1) {
            //     //自定义内容
            //     console.log('自定义内容', { eindex, prop, val, tdindex });
            //     if (wjval == 'wj') {
            //         tdindex += exportlist[eindex]['items'].filter(x => { return x.type == 'CP' }).length
            //         // console.log(cpcount,'cpcountcpcount');
            //         //  exportlist[eindex]['items'][tdindex+cpcount][prop] = value
            //     }

            //     exportlist[eindex]['items'][tdindex][prop] = value

            // } else {
            //     let index = exportlist[eindex]['items'].findIndex(x => { return x.id == id })
            //     exportlist[eindex]['items'][index][prop] = value;
            // }


       // }
    }

    // inputmobanchange1(prop, t, index, val) {

    //     // if(this.state.detail.pool!='BJ') return
    //     var value = prompt('请输入', val), { moban } = this.state
    //     if (value != val && value != '') {
    //         let tval = t == 0 ? 'cp' : 'wj'
    //         moban[tval][index][prop] = value;
    //         //  let {exportlist} = this.state,index = exportlist[eindex]['items'].findIndex(x=>{return x.id==id})
    //         this.setState({ moban })
    //     }
    // }






    render() {
        var { showpage1,showbtn,input_name,select_priceid,pricelist,select1id, showeditprice, sel_fang,showpage, fangjianhtml, moban, id,cate_MBXHhtml,cate_LSFShtml,cate_GTXHhtml,showmoban, input_mbname, detail, name, exportlist, totalamount, cate_WJLBhtml, roomhtml, selectroomid, cate_GTCZhtml } = this.state;
      //  console.log({cate_MBXHhtml,cate_GTXHhtml,cate_LSFShtml,cate_GTXHhtml}, 'render');

        let moban_amount = 0;
        moban.cp.forEach(x => {
            moban_amount += Math.round(((Number(x.height) * Number(x.width)) / 1000000) * Number(x.singleprice))
        })
        moban.wj.forEach(x => {
            moban_amount += Math.round(Number(x.count) * Number(x.singleprice))
        })
        moban.amount = moban_amount
      //  console.log(exportlist, 'exportlistexportlist');

        if (exportlist.length > 0) {
            exportlist.forEach(item => {
                let cptotalcount = 0, cptotal = 0, wjtotal = 0;

                item.items.cp.forEach(x => {
                    x.count = (x.unit == '米' ? (Number(x.width) / 1000) : ((Number(x.height) * Number(x.width)) / 1000000)) * this.getxs(x.deep)
                    if (x.unit == '扇') { x.count = 1 }
                    cptotalcount += Number(x.count)
                    cptotal = Math.round(Number(cptotal) + (Number(x.count) * Number(x.singleprice)))
                })
                item.items.wj.forEach(x => {
                    if(x.unit=='扇'){x.count=1}
                    wjtotal = Math.round(Number(wjtotal) + (Number(x.count) * Number(x.singleprice)))
                })
                item['cptotalcount'] = Number(cptotalcount).toFixed(2)
                item['cptotal'] = cptotal
                item['wjtotal'] = wjtotal
                item['amount'] = Math.round(Number(wjtotal) + Number(cptotal))
                totalamount = Math.round(Number(totalamount) + Number(wjtotal) + Number(cptotal))
            })
        }
        return (

            <div className="breadLinebox">
                <div>
                <div style={{border:'none',padding:'15px 0',fontSize:'26px',textAlign:'center'}} className="content">
                    {input_name}
                </div>

                <div style={{display:!showbtn?'none':''}} className="selfang">
                    {/* <p onClick={this.savemoban.bind(this)} className="btn">新增房间</p>
                    <p className="p1">选择房型</p>
                    <select value={sel_fang} onChange={this.selectfang.bind(this)}>  {fangjianhtml} </select>
                    <p onClick={this.addfangjian.bind(this)} className="btn">添加模板房型</p>
                    <p onClick={()=>{window.location.href='./dz_newroomdetail.html?id='+id}} className="btn">用户花色</p>
                    <p className="btn" style={{ 'cursor': 'pointer' }} onClick={() => {this.setState({showeditprice:!0}) }}>调整</p>
                    <p className="btn" style={{ 'cursor': 'pointer' }} onClick={()=>{
                                   this.export1()
                                }}>打印</p> */}
                                {/* <p onClick={()=>{this.export1.bind(this)}} className="btn">打印</p> */}
                                {/* <p onClick={()=>{window.location.href='./dz_main.html'}} className="btn">返回</p> */}
                </div>

                <div className='content_wrap panel-default content_wrap ' style={{padding:showpage?'0':'10px 30px'}}>


                    <div style={{border:showpage?'none':'',padding:showpage?'0':'10px 30px'}} className="content form">
                        {/* <div style={{display:clicknew?"":"none"}} id="div"> */}
                        <div className="titlet">{this.state.detail.name}</div>
                        {
                            exportlist.map((x, exportindex) => {
                                return (
                                    <div>

                                        <div style={{border:showpage?'none':'',margin:showpage?'0':'',padding:showpage?'0':'10px 30px'}} className="content form">
                                            <div className="deldiv">
                                                <p>{x.name}</p>
                                            </div>
                                            <table className="tab">
                                                <thead>
                                                    <tr>
                                                        {/* <th className="minwidth tconter"><img src="./src/notselection.png"/></th> */}

                                                        <th style={{display:showpage?'none':''}} className="tconter td0">序号</th>
                                                        <th className="tconter td1"> <div >产品类型</div></th>
                                                        <th className="tconter td2"><div >宽度</div></th>
                                                        <th className="tconter td2"><div >高度</div></th>
                                                        <th className=" tconter td2"><div >深度</div></th>
                                                        <th className=" tconter td2"><div >数量</div></th>
                                                        <th className=" tconter td2"><div >单位</div></th>
                                                        <th className=" tconter td2"><div >单价</div></th>
                                                        <th className=" tconter td2"><div >总价</div></th>
                                                        <th className=" tconter td1"><div >立面说明</div></th>
                                                        <th className=" tconter td3"><div className="td1">拉手方式</div></th>
                                                        <th className=" tconter td3"><div className="td3">门板/柜体材质</div></th>
                                                        <th className=" tconter td3"><div className="td1">门板型号</div></th>
                                                        <th className=" tconter td3"><div className="td1">柜体型号</div></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    {

                                                        x.items.cp.map((item_cp, index) => {
                                                            let xs = this.getxs(item_cp.deep)
                                                            let count = (item_cp.unit == '米' ? (Number(item_cp.width) / 1000) : ((Number(item_cp.height) * Number(item_cp.width)) / 1000000)) * xs
                                                            if(item_cp.unit=='扇'){  count=1 }
                                                            return (
                                                                <tr key={index}>
                                                                    {/* <td className="minwidth tconter"><img src="./src/notselection.png"/></td>  */}
                                                                    {/* <td className="tconter">{x.state=="0"?"显示":"隐藏"}</td>  */}
                                                                    <td style={{display:showpage?'none':''}} className="tconter td0">{index + 1}</td>
                                                                    <td onClick={this.inputchange1.bind(this, exportindex, 'cname', item_cp.cname, index, 'cp')} className="tconter td1">
                                                                        <div>{item_cp.cname}</div>
                                                                        
                                                                    </td>
                                                                    <td onClick={this.inputchange1.bind(this, exportindex, 'width', item_cp.width, index, 'cp')} className="tconter td2">
                                                                    <div >{item_cp.width}</div>
                                                                        </td>
                                                                    <td onClick={this.inputchange1.bind(this, exportindex, 'height', item_cp.height, index, 'cp')} className="tconter td2">
                                                                    <div >{item_cp.height}</div>
                                                                        </td>
                                                                    <td onClick={this.inputchange1.bind(this, exportindex, 'deep', item_cp.deep, index, 'cp')} className="tconter td2">
                                                                    <div >{item_cp.deep}</div>
                                                                       </td>
                                                                    <td className="tconter td2">{
                                                                         <div >{count.toFixed(2)}</div> 
                                                                        }</td>
                                                                    <td className="tconter td2">
                                                                    <div >{item_cp.unit}</div>
                                                                        </td>
                                                                    <td onClick={this.inputchange1.bind(this, exportindex, 'singleprice', item_cp.singleprice, index, 'cp')} className="tconter td2">
                                                                        <div className="td2">{item_cp.singleprice}</div>
                                                                        </td>
                                                                    <td className="tconter td2">
                                                                    <div > {Math.round(Number(item_cp.singleprice) * count)}</div>
                                                                        
                                                                        </td>
                                                                    
                                                                    <td onClick={this.inputchange1.bind(this, exportindex, 'lmsm', item_cp.lmsm, index, 'cp')} className="tconter td3">
                                                                        <div >{item_cp.lmsm}</div></td>
                                                                   
                                                                    <td  className="tconter td3"><div className="td1">
                                                                       {item_cp.LSFSname}
                                                                       </div>
                                                                    </td>

                                                              
                                                                    <td  className="tconter td3">
                                                                    <div className="td3"> 
                                                                       {item_cp.cname1==-1?'':item_cp.cname1}
                                                                    </div>
                                                                    </td>

                                                                  
                                                                    <td  className="tconter td3">
                                                                    <div className="td1">
                                                                       {item_cp.MBXHname||''}
                                                                    </div>
                                                                    </td>

                                                                  
                                                                    <td  className="tconter td3">
                                                                    <div className="td1">
                                                                       {item_cp.GTXHname}

                                                                    </div>
                                                                    </td>


                                                                    {/* <td className="tconter w80"> {item_cp.cname1}</td> */}
                                                                  

                                                                </tr>
                                                            )

                                                        })
                                                    }
                                                </tbody>
                                            </table>
                                            {/* <div className="tongji">
                                                <div>
                                                <p> 数量合计：{x.cptotalcount}</p>
                                                <p> 合计：{x.cptotal}</p>
                                                </div>
                                                    
                                               
                                            </div> */}


                                            <table className="tab">
                                                <thead>
                                                    <tr>
                                                        {/* <th className="minwidth tconter"><img src="./src/notselection.png"/></th> */}

                                                        <th style={{display:showpage?'none':''}} className="tconter td0">序号</th>
                                                        <th  className="tconter td1"><div  >五金类别</div></th>
                                                        <th className=" tconter td2"><div  >宽度</div></th>
                                                        <th className=" tconter td2"><div  >高度</div></th>
                                                        <th className=" tconter td2"><div  >深度</div></th>
                                                        <th className=" tconter td2"><div  >数量</div></th>
                                                        <th className=" tconter td2"><div  >单位</div></th>
                                                        <th className=" tconter td2"><div  >单价</div></th>
                                                        <th className=" tconter td2"><div  >总价</div></th>
                                                        <th className=" tconter td1"><div  >立面说明</div></th>
                                                        <th className=" tconter td3"><div  >备注</div></th>
                                                        <th className=" tconter td3"><div  ></div></th>
                                                        <th className=" tconter td3"><div  ></div></th>
                                                        <th className=" tconter td3"><div  ></div></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    {
                                                        x.items.wj.map((item_cp, i) => {
                                                            return (
                                                                <tr key={i}>
                                                                    {/* <td className="minwidth tconter"><img src="./src/notselection.png"/></td>  */}
                                                                    {/* <td className="tconter">{x.state=="0"?"显示":"隐藏"}</td>  */}
                                                                    <td style={{display:showpage?'none':''}} className="tconter td0">{i + 1}</td>
                                                                    {/* <td className="tconter w80">
                                                                    {item_cp.cname1}
                                                                    </td> */}
                                                                    <td className="tconter td2">
                                                                    <div className="td1">
                                                                       {item_cp.cname1}

                                                                    </div>
                                                                    </td>
                                                                    <td className="tconter td2">
                                                                        <div className="td2">
                                                                        -
                                                                        </div>
                                                                        </td>
                                                                    <td className="tconter td2"><div className="td2">-</div></td>
                                                                    <td className="tconter td2"><div className="td2">-</div></td>
                                                                    <td onClick={this.inputchange1.bind(this, exportindex, 'count', item_cp.count, i, 'wj')} className="tconter"><div className="td2">
                                                                    {item_cp.count}
                                                                        </div></td>
                                                                    <td className="tconter td2"><div className="td2">{item_cp.unit}</div></td>
                                                                    <td onClick={this.inputchange1.bind(this, exportindex, 'singleprice', item_cp.singleprice, i, 'wj')} className="tconter td2"><div className="td2">{item_cp.singleprice}</div></td>
                                                                    <td className="tconter"><div className="td2">{Math.round(Number(item_cp.singleprice) * Number(item_cp.count))}</div></td>
                                                                    <td onClick={this.inputchange1.bind(this, exportindex, 'lmsm', item_cp.lmsm, i, 'wj')} className="tconter w80"><div className="td1">

                                                                        {item_cp.lmsm}
                                                                        </div>
                                                                        </td>
                                                                    <td className="tconter td3"> <div className="td2">
                                                                        {item_cp.cname}
                                                                        </div>
                                                                        </td>
                                                                        <td className="tconter td3"><div className="td3">-</div></td>
                                                                        <td className="tconter td3"><div className="td1">-</div></td>
                                                                        <td className="tconter td3"><div className="td1">-</div></td>
                                                                   
                                                                </tr>
                                                            )

                                                        })
                                                    }
                                                </tbody>
                                            </table>
                                            {/* <div className="tongji">
                                                <div>
                                                <p> 合计：{x.wjtotal}</p>
                                                </div>

                                            </div> */}
                                            <div className="tongji he">
                                                <p>合计金额：{x.amount}</p>
                                            </div>

                                        </div>
                                    </div>

                                )
                            })
                        }


                        <div className="tabletit" >

                            {/* <select value={selectroomid} onChange={this.selectchange.bind(this)}>{roomhtml} </select>

    <p className="add" style={{'cursor':'pointer'}} onClick={this.addroom.bind(this)}>添加</p> */}
   

                            <p>总金额：{totalamount}</p>
                            <div style={{display:showbtn?'':'none'}}>
                                {/* <p className="add" style={{ 'cursor': 'pointer' }} onClick={()=>{
                                    this.setState({showbtn:!0})
                                }}>隐藏按钮</p> */}
                                   <p className="add" style={{ 'cursor': 'pointer' }} onClick={this.export1.bind(this)}>打印</p>
                                {/* <p className="add" style={{ 'cursor': 'pointer' }} onClick={this.save.bind(this)}>保存</p> */}
                                <p className="add" style={{ 'cursor': 'pointer' }} onClick={() => { window.location.href = './dz_main.html' }}>返回</p>
                                
                            </div>
                            {/* <div style={{display:showbtn?'none':''}}>
                            <p className="add" style={{ 'cursor': 'pointer' }} onClick={()=>{
                                    this.setState({showbtn:!0})
                                }}>显示</p>
                            </div> */}
                        </div>



                    </div>

                </div >
                </div>

            </div >


        )
    }
}





ReactDOM.render(
    <div>
        {/* <LeftMenu code='0' /> */}
        <FirstPage />
    </div>
    //<Barrage/>
    , $('.container')[0]
)